//
//  AddressManagerCell.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/4/14.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "AddressManagerCell.h"
#import "AddressEditView.h"
#import "AddressEntity.h"

@interface AddressManagerCell ()

@property (nonatomic, strong) AddressEditView *addressView;

@end

@implementation AddressManagerCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupSubViews];
    }
    return self;
}

- (void)setIsDefalut:(BOOL)isDefalut
{
    _isDefalut = isDefalut;
    self.addressView.isDefalut = isDefalut;
}

- (void)setAddressEntity:(AddressEntity *)addressEntity
{
    _addressEntity = addressEntity;
    self.addressView.nameLab.text = addressEntity.receContact;
    self.addressView.telLab.text = addressEntity.receTel;
    
    if (addressEntity.isDefult.intValue == 1) {
        //默认
        self.addressView.isDefalut = YES;
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.firstLineHeadIndent = 35;
        NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:addressEntity.receAddress attributes:@{NSForegroundColorAttributeName:kColor333333,NSParagraphStyleAttributeName:paragraph}];
        self.addressView.addressLab.attributedText = attribute;
    }
    else {
        self.addressView.isDefalut = NO;
        NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:addressEntity.receAddress attributes:@{NSForegroundColorAttributeName:kColor333333}];
        self.addressView.addressLab.attributedText = attribute;
    }
}


- (void)setupSubViews
{
    self.backgroundColor = [UIColor clearColor];
    
    self.addressView = [[AddressEditView alloc] init];
    [self addSubview:self.addressView];
    [self.addressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.bottom.equalTo(self);
    }];
    WeakSelf
    self.addressView.editHandler = ^{
        if (weakSelf.editHandler) {
            weakSelf.editHandler();
        }
    };
}

@end
